package com.pwc.conversionTool.dao;

import java.util.List;

import com.googlecode.objectify.Key;
import com.pwc.conversionTool.entity.Account;
import com.pwc.conversionTool.entity.Operation;
import com.pwc.conversionTool.entity.Project;

import static com.pwc.conversionTool.entity.service.OfyService.ofy;

public class ProjectDao {
	
	public Key<Project> saveProject(Project project)
	{
		return ofy().save().entity(project).now();
	}

	public Project getProjectById(Long id) {
		
		return ofy().load().type(Project.class).id(id).now();
	}

	public List<Project> getProjectsByAccount(Account currentAccount) {
		
		return ofy().load().type(Project.class).filter("account", currentAccount).list() ;
	}

	public void saveOperation(Operation operation) {
		
		ofy().save().entity(operation).now();
	}

	public List<Operation> findOperationByProject(Key<Project> key) {
		
		return ofy().load().type(Operation.class).filter("project", key).list();
		
	}

	public void deleteOperation(Operation operation) {
		
		ofy().delete().entity(operation).now();
	}

	public void deleteProject(Project project) {

		
		ofy().delete().entity(project).now();
	}

	public List<Operation> getOperationsByProject(Key<Project> key) {
		
		return ofy().load().type(Operation.class).filter("project", key).list();
	}


	
	public void deleteOperationById(Long id)
	{
		ofy().delete().type(Operation.class).id(id).now();
	}

	
	
	public Operation getOperationById(Long operationId) {
		
		return ofy().load().type(Operation.class).id(operationId).now();
		
	}

	public Operation getOperationByKey(Key<Operation> operationKey) {
		
		return ofy().load().key(operationKey).now();
	}
	

}
